package es.cazadoresmadridejos.web.tags.functions;

import java.util.Calendar;

public class MonthFunction {

	private static int[] days = {31,28,31,30,31,30,31,31,30,31,30,31};

	public static int firstDay(int year, int month){
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.MONTH, month);
		cal.set(Calendar.YEAR, year);
		cal.set(Calendar.DAY_OF_MONTH, 0);
		return cal.get(Calendar.DAY_OF_WEEK);
	}

	public static int days(int year, int month){
		if(month == 1){
			if(year % 4 == 0){
				return 29;
			}
		}
		return days[month];
	}

	public static int rows(int year, int month){
		if(month == 1){
			if(year % 4 == 0){
				return 29;
			}
		}
		int ndays = days[month];
		ndays += firstDay(year, month);
		
		int rows = ndays / 7;
		if(ndays % 7 != 0){
			rows++;
		}
		
		return rows;
	}

	public static void main(String[] args) {
		System.out.println(firstDay(2012, 0));
		System.out.println(firstDay(2012, 1));
		System.out.println(firstDay(2012, 2));
		System.out.println(firstDay(2012, 3));
		System.out.println(firstDay(2012, 4));
		System.out.println(firstDay(2012, 5));

		System.out.println(days(2012, 0));
		System.out.println(days(2012, 1));
		System.out.println(days(2012, 2));
		System.out.println(days(2012, 3));
		System.out.println(days(2012, 4));
		System.out.println(days(2012, 5));


	}
}
